home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / bas_int1.zip / F_EXIST.BAS < prev    next >
BASIC Source File  |  1991-06-30  |  2KB  |  51 lines

  1. '=====================================================================
  2. 'Quick Basic Forum
  3. '   Date : 26-Jun-91
  4. '   From : Mike Kelly
  5. 'Subject : If Exist (file$) then
  6. '======================================================================
  7.  
  8. 'EXIST.BAS
  9.  
  10. ' $INCLUDE: 'QB.BI'            
  11. ' ----------------- Standard $INCLUDE (start QB with "/L")
  12. DECLARE FUNCTION Exist% (File$)  'Declare the Function
  13. CLS                              'Clear Screen
  14. Search$ = "exist.bas"            'Set file to search for
  15. IF Exist%(Search$) THEN          'If it's there then
  16.   PRINT "OK file!"               '  Do this
  17.  ELSE                            ' or if not then
  18.   PRINT "Bad File!"              '  Do this and
  19.   SYSTEM                         '  Quit or whatever
  20. END IF
  21.  
  22. FUNCTION Exist% (File$)
  23.   DIM reg AS RegTypeX        'Intialize
  24. ' --------------------------- Get Current DTA address
  25.   reg.ax = &H2F00            'Function 2FH (Get current DTA)
  26.   INTERRUPTX &H21, reg, reg  'Interrupt 21
  27.   Sgmt% = reg.es             'DTA Segment
  28.   Ofst% = reg.bx             'DTA Offset
  29. ' --------------------------- Set DTA address for desired file
  30.   Buffer$ = SPACE$(43)       'Initialize Buffer
  31.   reg.ax = &H1A00            'Function 1AH (Set DTA)
  32.   reg.ds = VARSEG(Buffer$)   'Segment of Buffer
  33.   reg.dx = SADD(Buffer$)     'Offset of Buffer
  34.   INTERRUPTX &H21, reg, reg  'Interrupt 21
  35. ' --------------------------- Check if file is there
  36.   File$ = File$ + CHR$(0)    'End it with a null
  37.   reg.ax = &H4E00            'Function 4EH (Search for 1st match)
  38.   reg.cx = 103               'File attribute is *anything*
  39.   reg.ds = VARSEG(File$)     'Segment of PathFile$
  40.   reg.dx = SADD(File$)       'Offset of PathFile$
  41.   INTERRUPTX &H21, reg, reg  'Interrupt 21
  42.   result% = reg.flags AND 1  'Make results usable
  43. ' --------------------------- Restore original DTA
  44.   reg.ax = &H1A00            'Function 1AH (Set DTA)
  45.   reg.ds = Sgmt%             'Original segment
  46.   reg.dx = Ofst%             'Original offset
  47.   INTERRUPTX &H21, reg, reg  'Interrupt 21
  48.   Exist% = result% - 1       'Equate Function to result
  49. END FUNCTION
  50.  
  51.